package com.fmy.mcsecurity.login.safety.violence;


import lombok.AllArgsConstructor;

/**
 * <p>
 * 防止暴力破解
 * </p>
 *
 * @author Mr.Fmy
 * @since 2020-12-10
 */
@AllArgsConstructor
public class SafetyViolenceService {

    private final SafetyViolenceStorage safetyViolenceStorage;

    /**
     * 传入用户名，检测是否需要禁止登录
     */
    public void valition(String username) {
        safetyViolenceStorage.valitionAstrictLogin(username);
    }

    public void setSafetyViolence(String type, String username) {
        int i = safetyViolenceStorage.get(username);
        SafetyViolence safetyViolence = safetyViolenceStorage.getSafetyViolence(i);
        if (safetyViolence != null) {
            safetyViolenceStorage.astrictLogin(username, safetyViolence);
        } else {
            safetyViolenceStorage.set(username);
        }
    }
}
